

message("----------QMCRT cmake begins----------")

# required cmake version
cmake_minimum_required(VERSION 3.10)



if(NOT DEFINED CMAKE_CUDA20_STANDARD_COMPILE_OPTION)
  set(CMAKE_CUDA20_STANDARD_COMPILE_OPTION "")
  set(CMAKE_CUDA20_EXTENSION_COMPILE_OPTION "")
endif()


# cuda 库
set(CUDA_SEPARABLE_COMPILATION ON)
set(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda-12.0")

find_package(CUDA REQUIRED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
message("CUDA_TOOLKIT_ROOT_DIR: ${CUDA_TOOLKIT_ROOT_DIR}")
message("cuda version: ${CUDA_VERSION_STRING}")
message(STATUS "CUDA libraries: ${CUDA_LIBRARIES}")
message(STATUS "CUDA include path: ${CUDA_INCLUDE_DIRS}")
set(CUDA_NVCC_FLAGS -gencode arch=compute_20,code=sm_20;-G;-g)
include_directories(${CUDA_INCLUDE_DIRS})
link_directories( ${CUDA_LIBRARY_DIRS})

# packages
# set(CUDA_SEPARABLE_COMPILATION ON)
# find_package(CUDA REQUIRED)




set(SOURCE_DIR "/home/liu/Git_resposity/solar/solar_software/solar_2/source")
set(RAYTRACING_DIR "${SOURCE_DIR}/rayTracing")

#自动查找头文件路径函数
macro(FIND_INCLUDE_DIR result curdir)  #定义函数,2个参数:存放结果result；指定路径curdir；
    file(GLOB_RECURSE children "${curdir}/*.hpp" "${curdir}/*.h" "${curdir}/*.cuh" ) # 遍历获取{curdir}中*.hpp和*.h文件列表
    # message(STATUS "children= ${children}")								# 打印*.hpp和*.h的文件列表
    set(dirlist "")														# 定义dirlist中间变量，并初始化
    foreach(child ${children})											# for循环
        string(REGEX REPLACE "(.*)/.*" "\\1" LIB_NAME ${child})			# 字符串替换,用/前的字符替换/*h
        if(IS_DIRECTORY ${LIB_NAME})									# 判断是否为路径
            LIST(APPEND dirlist ${LIB_NAME})							# 将合法的路径加入dirlist变量中
        endif()															# 结束判断
    endforeach()														# 结束for循环
    list(REMOVE_DUPLICATES dirlist)                                     # 删除重复的文件夹
    set(${result} ${dirlist})											# dirlist结果放入result变量中
endmacro()																# 函数结束


#查找include目录下的所有*.hpp,*.h,*.cuh头文件,并路径列表保存到 INCLUDE_DIR_LIST 变量中
FIND_INCLUDE_DIR( RAYTRACING_INCLUDE_DIR_LIST ${RAYTRACING_DIR})			# 调用函数，指定参数
# message(STATUS "RAYTRACING_INCLUDE_DIR_LIST= ${RAYTRACING_INCLUDE_DIR_LIST}")
#将INCLUDE_DIR_LIST中路径列表加入工程		
include_directories(   												# INCLUDE_DIR_LIST路径列表加入工程
        ${RAYTRACING_INCLUDE_DIR_LIST}
)



file(GLOB_RECURSE raytracing_native_srcs 
    ${RAYTRACING_DIR}/*.cpp 
    ${RAYTRACING_DIR}/*.h
    ${RAYTRACING_DIR}/*.in
    ${RAYTRACING_DIR}/*.cu
    ${RAYTRACING_DIR}/*.cuh

)

add_library(quasiMonteCarloRayTracing SHARED 
    ${raytracing_native_srcs}
)


# target_include_directories(quasiMonteCarloRayTracing PUBLIC "${UISOURCE_DIR}/scene")
# target_include_directories(quasiMonteCarloRayTracing PUBLIC "${UISOURCE_DIR}/topology")
# target_include_directories(quasiMonteCarloRayTracing PUBLIC "${UISOURCE_DIR}/tree")
# # target_include_directories(quasiMonteCarloRayTracing PUBLIC "${UISOURCE_DIR}/utils")
# # target_include_directories(quasiMonteCarloRayTracing PUBLIC "${UISOURCE_DIR}/world")
# target_include_directories(quasiMonteCarloRayTracing PUBLIC "${UISOURCE_DIR}/window/simulationWindow")
# target_include_directories(quasiMonteCarloRayTracing PUBLIC "/home/liu/Git_resposity/solar/solar_software/solar_2/third_party/vectorclass2")
# target_link_libraries(quasiMonteCarloRayTracing uiclass)


# target_compile_options(quasiMonteCarloRayTracing PRIVATE "-std=c++17")

# target_link_libraries(quasiMonteCarloRayTracing PRIVATE ${CUDA_LIBRARIES} ${CUDA_cudadevrt_BIBRARY})
message("----------QMCRT cmake ends----------")


